package com.gillion.tms.entity;

import com.gfa4j.security.data.entity.ITable;
import com.gfa4j.security.domain.IRole;
import com.gfa4j.security.domain.IUser;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;

import java.io.Serializable;
import java.util.Collection;
import java.util.Set;

public class User implements IUser, Serializable {

    private static final long serialVersionUID = -7216838057325845828L;
    private String             userId;
    private String             username;
    private String             password;
    private Collection<ITable> tables;

    @Override
    public Collection<ITable> getPermissionTables() {
        return tables;//DataPermissionUtils.loadTableByUser(this.getUsername());
    }

    private Set<String> hasPermissionUrlPatterns;

    public void setUserId(String userId) {
        this.userId = userId;
    }

    @Override
    public String getUserId() {
        return userId;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public Collection<IRole> getAuthorities() {
        return Lists.newArrayList();
    }

    @Override
    public void setAuthorities(Iterable<? extends IRole> roles) {

    }

    public String getPassword() {
        return password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public boolean isAccountNonExpired() {
        return true;
    }

    public boolean isAccountNonLocked() {
        return true;
    }

    public boolean isCredentialsNonExpired() {
        return true;
    }

    public boolean isEnabled() {
        return true;
    }

    public void setHasPermissionUrlPatterns(Iterable<String> hasPermissionUrlPatterns) {
        this.hasPermissionUrlPatterns = ImmutableSet.copyOf(hasPermissionUrlPatterns);
    }

    @Override
    public Set<String> getHasPermissionUrlPatterns() {
        return hasPermissionUrlPatterns;
    }

}